package club.emergency.wechat.resource_study.operate.consumer.service.fallback_factory;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.model.resource_study.ResourceStudy;
import club.emergency.wechat.resource_study.operate.consumer.service.ResourceStudyOperateConsumer;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.resource_study.operate.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class ResourceStudyOperateFallbackFactory implements FallbackFactory<ResourceStudyOperateConsumer> {
    @Override
    public ResourceStudyOperateConsumer create(Throwable throwable) {
        return new ResourceStudyOperateConsumer() {
            @Override
            public String uploadFile(byte[] bytes, String extName, String fileName) {
                return ResponseEntity.error(StatusCode.UPLOAD_FILE_ERROR, "上传资料学习文件失败！", throwable.getMessage());
            }

            @Override
            public String deleteFile(Long id) {
                return ResponseEntity.error(StatusCode.DELETE_FILE_ERROR, "删除资料学习文件失败！", throwable.getMessage());
            }

            @Override
            public String save(ResourceStudy resourceStudy) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "新增资料学习记录失败！", throwable.getMessage());
            }

            @Override
            public String modify(ResourceStudy resourceStudy) {
                return ResponseEntity.error(StatusCode.DB_MODIFY_ERROR, "修改资料学习记录失败！", throwable.getMessage());
            }

            @Override
            public String remove(ResourceStudy resourceStudy) {
                return ResponseEntity.error(StatusCode.DB_REMOVE_ERROR, "删除资料学习记录失败！", throwable.getMessage());
            }
        };
    }
}
